<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="ISO-8859-1"%>
<%@ page import="schronisko.*,Users.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../styles/panels.css">
<style type="text/css">

table, td, th
{
border:1px solid green;
padding: 1px;
}
th
{
background-color:green;
color:white;
}
</style>
<title>Panel</title>
</head>
<body>
<div class='tlo'>
<img src="../Images/anim10.jpg">
	<%
	Queries q = new Queries();
	session.setMaxInactiveInterval(60*60); // godzina
	session.setAttribute("function", "edit_profile");
		if ((session.getAttribute("session_id") != null)) {
			int type = (Integer) session.getAttribute("type");
			int temp = (Integer) session.getAttribute("temp");
			response.setContentType("text/html");
			String username = (String) session.getAttribute("username");
			session.setAttribute("detailed_w_list", q.getDetailedWorkers());
			session.setAttribute("balanse_f", "promote");
			if (username != null) {
				if (type == 3 && temp == 0) { // Menu szefa
				%>
				<div class='menu'>
					<center>
						<h4>
							<font color='green'>Dostepne opcje:</font>
						</h4>
					</center>
					<ul>
						<li><a href='../Redirect_k' class='a'>Funkcje klienta </a><br>
						</li>
						<li><a href='../Redirect_w' class='a'>Funkcje pracownika </a><br></li>
						<li><a href='../Redirect_a' class='a'>Funkcje admina </a><br></li>
						<li><a href='../chef/bilanse.jsp' class='a'> Przegladaj
								bilans </a><br></li>
						<li><a href='../chef/promote.jsp' class='a'> Awansuj </a><br></li>
						<li><b><a href='../index.jsp' class='a'> Powrot do
									glownej </a></b><br></li>
					</ul>
				</div>
				<%
					}
				%>
	<div class='panel'>
		<center>
		<br>
		<b>Aktualni pracownicy:</b>
		<table>
		<tr>
		<th>Imie</th>
		<th>Nazwisko</th>
		<th>Prawa</th>
		</tr>
		<% String[] worker = (String[])session.getAttribute("detailed_w_list"); 
				int i =0;
				while(i < worker.length){
					if(Integer.parseInt(worker[i+2]) == 1)
						worker[i+2] = "Pracownik";
					else if(Integer.parseInt(worker[i+2]) == 2)
						worker[i+2] = "Administrator";
					else if(Integer.parseInt(worker[i+2]) == 3)
						worker[i+2] = "Szef";
					out.println("<tr>" + "<td>"+ worker[i] + "</td><td> " + worker[i+1] + "</td><td>" +worker[i+2] + "</td></tr>");
					i+=3;
				}%>
		</table><br><br><font color='red'>
		
		<%
			int success = (Integer)session.getAttribute("transaction");
			if(success == 1){
				if((Integer)session.getAttribute("success") == 1)
					out.println("Nadanie praw zakonczone sukcesem");
				else out.println("Nie udalo sie nadac. Brak pracownika");
				session.setAttribute("transaction", 0);
			}
			else if(success == 2){
				out.println("Nalezy podac dwuczlonowa nazwe <br>(Imie Nazwisko)");
				session.setAttribute("transaction", 0);
			}
			else if(success == 3){
				out.println("Nalezy podac PESEL");
				session.setAttribute("transaction", 0);
			}
			else if(success == 4) {
				out.println("PESEL ma miec 11 znakow");
				session.setAttribute("transaction", 0);
			}
			%>
		</font>
			<form name='promote'
					action='../Chef_functions'
					method=POST>
					<h4>
			Wpisz imie i nazwisko osoby, ktora chcesz awansowac/degradowac: <br><br>
			<input id='client' name='client' type="text" size =30>
			<br><br>
			Podaj jej PESEL:<br>
			<input id='pesel' name='pesel' type="text" size =30>
			<br>
			<br>
			Wybierz nowe prawa :<br><br>
			<select id='type' name='type'>
			<option>Klient</option>
			<option>Pracownik</option>
			<option>Administrator</option>
			<option>Szef</option>
			</select>
			<br><br>
			<input type="submit" value="Potwierdz"><br>
			</h4>
			</form>
			
			
			
			
			
		</center>
	</div>


	<div class='logged'>
		<center>
			<h3>
				Zalogowany jako
				<%
				out.println("<font color='red'>" + username + "</font>");
			%>
				!
			</h3>

		</center>
		<center>
			<h4>
				<a href='../logout.jsp'> Wyloguj </a>
			</h4>
		</center>
	</div>

	<div class='zalogowany'>
		<center>
			<h1>
				Prawa
				<%
				switch (type) {
						case 1:
							out.println("pracownika");
							break;
						case 2:
							out.println("admina");
							break;
						case 3:
							out.println("szefa");
							break;
						}
			%>
			</h1>
		</center>
	</div>
	<%
		}
		} else {
			out.println("<div class='menu'><b>Sesja wygasla.</b><br> Za 3 sec nastapi przeniesienie do strony logowania <br> Kliknij, jesli nie zadziala:<br> <a href = '../index.jsp'> Wroc do strony glownej</a></div>");
			response.setHeader("Refresh", "3; URL=../index.jsp");
		}
	%>
</div>
</body>
</html>